<?php

/**
 * 飞书员工加盟名片功能路由
 */

/*** 飞书小程序 ***/

use App\Http\Controllers\CallingCards\RMS\FranchiseeController;
use App\Http\Controllers\CallingCards\RMS\InvestmentEmployeeController;
use App\Http\Controllers\CallingCards\Wechat\CallingCardController;
use App\Http\Controllers\CallingCards\Wechat\StoryController;
use App\Http\Controllers\CallingCards\RMS\StoryController as RmsStoryController;
use App\Http\Middleware\CallingCards\WechatAppletAuth;
use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'feishu', 'namespace' => 'Feishu'], function () {
    Route::post('login/login', 'LoginController@login');
    Route::group(['middleware' => 'callingCards.feishuAuth'], function () {
        Route::get('card/index', 'CardController@index'); //名片信息
        Route::get('card/backgrounds', 'CardController@backgrounds'); //新的背景图列表
        Route::post('card/save', 'CardController@save');  //修改名片信息
        Route::post('card/updateBackground', 'CardController@updateBackground');  //修改名片背景图
        Route::get('card/myClue', 'CardController@getMyClue');  //我的线索
    });
});

/*** 微信小程序小程序 ***/
Route::group(['prefix' => 'wechat', 'namespace' => 'Wechat'], function () {
    Route::post('login/login', 'LoginController@login');
    Route::group(['middleware' => 'callingCards.wechatAuth'], function () {
        Route::post('franchisee/save', 'FranchiseeController@save'); //提交加盟商线索
        Route::get('callingCard', 'CallingCardController@detail'); // 获取名片信息
        Route::get('story/detail', 'StoryController@detail'); // 通过文章id获取文章url
        Route::post('story/shareImage', 'StoryController@shareImage'); // 生成文章分享海报
        Route::post('source/record', 'SourceController@record'); // 访客来源
//        Route::post('updateUser', [CallingCardController::class, 'updateUser']); // 微信小程序用户更新信息
        Route::post('story/article', [StoryController::class, 'article']); // 文章阅读事件
        Route::post('customer', [CallingCardController::class, 'updateUserMobile']); // 微信小程序用户授权更新用户手机号
    });
    Route::get('franchisee/articles', 'FranchiseeController@articles'); // 加盟说、品牌介绍
    Route::get('franchisee/areas', 'FranchiseeController@areas'); // 两级地址
    Route::get('product/index', 'ProductController@index'); // 串品列表
    Route::get('story', 'StoryController@index');//加盟商故事列表，来自公众号文章索引

});

/*** RMS ***/
Route::group(['prefix' => 'rms', 'namespace' => 'RMS'], function () {
    Route::group(['middleware' => \App\Http\Middleware\CallingCards\RmsAuth::class], function () {
        Route::get('franchisee/articles', 'FranchiseeController@articles');  //加盟说
        Route::post('franchisee/saveArticle', 'FranchiseeController@saveArticle');  //新建、修改加盟说
        Route::post('franchisee/articleStatus', 'FranchiseeController@articleStatus');  //新建、修改加盟说
        Route::get('story/lists', [RmsStoryController::class, 'lists']);  // 文章数据看板
        Route::get('story/getReadArticleUses', [RmsStoryController::class, 'getReadArticleUses']);  // 文章数据看板-查看人员名单
    });

    Route::get('background', 'BackgroundController@index')->middleware('rms.backend');
    Route::post('background/save', 'BackgroundController@save');
    Route::post('background/update', 'BackgroundController@update');
    Route::post('background/delete', 'BackgroundController@delete');
    Route::post('background/announcementSave', 'BackgroundController@announcementSave');
    Route::post('background/ruleSave', 'BackgroundController@ruleSave');
    //修改推荐夸父主页图片
    Route::post('homeImg/save', 'BackgroundController@homeImg');
    //修改推荐夸父详情页图片
    Route::post('detailImg/save', 'BackgroundController@detailImg');

    // 销氪管理
    Route::prefix('investment')->group(function(){
        Route::get('/', [InvestmentEmployeeController::class, "index"])->middleware('rms.backend');
        Route::post('/', [InvestmentEmployeeController::class, "insert"]);
        Route::post('/{id}', [InvestmentEmployeeController::class, "update"])->where('id', '[0-9]+');
        Route::delete('/{id}', [InvestmentEmployeeController::class, "del"])->where('id', '[0-9]+');
    });
    Route::get('investment', [InvestmentEmployeeController::class, "index"]);
    Route::post('investment/saveAll', 'InvestmentEmployeeController@saveAll');

    Route::get('home/homeArticleForm', [FranchiseeController::class, "homeArticleForm"]); // 官网文章添加表单获取
    Route::post('homeArticle', [FranchiseeController::class, "homeArticleAdd"]); // 官网文章添加
    Route::get('homeArticle/{id}', [FranchiseeController::class, "homeArticleEditForm"]); // 官网文章编辑表单获取
    Route::put('homeArticle/{id}', [FranchiseeController::class, "homeArticleEdit"]); // 官网文章编辑保存
});

/*** 官网 ***/
Route::group(['prefix' => 'officialWeb', 'namespace' => 'OfficialWeb'], function () {
    Route::post('franchisee/record', 'FranchiseeController@record');
    Route::post('franchisee/thirdPartyRecord', 'FranchiseeController@thirdPartyRecord');
});

/*** 商家APP ***/
Route::group(['prefix' => 'merchant', 'namespace' => 'Merchant', 'middleware' => \App\Http\Middleware\CallingCards\MerchantAppAuth::class], function () {
    Route::get('userInfo', 'CallingCardsController@getCallingCardsInfoByUser');
    Route::get('background/index', 'BackgroundController@index');
    Route::post('background/upload', 'BackgroundController@upload');
    Route::post('background/makePoster', 'BackgroundController@makePoster');
});

/*** 微信服务号文章 ***/
Route::group(['prefix' => 'wechatOfficial', 'namespace' => 'wechatOfficial'], function () {
    Route::get('info/{id}', [FranchiseeController::class, 'getArticleInfo']);  // 微信服务号文章信息

    Route::group(['middleware' =>WechatAppletAuth::class], function () {
        Route::post('/article', [FranchiseeController::class, 'article']);         // 文章阅读事件
    });
});
